<?php
class PostIndexAction extends AdminAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'tpl';
		$this->layout = 'admin';
	}

	public function execute()
	{
		$page		= $this->getPage();
		$tmp	 	= LtObjectUtil::singleton('LtConfig')->get('pagination.pager');
		$pageSize	= $tmp['per_page'];
		if (empty($pageSize))
		{
			$pageSize 	= 20;
		}
		$num 			= $pageSize;
		$start	 		= ($page-1) * $pageSize;
		
		$con					= array();
		$type					= $this->context->get('type');
		if($type=='comment')
		{
			$con['type']		= 0;
		}
		else
		{
			$con['pid']			= 0;
		}
		$this->data['type']		= $type;
		$postService			= new PostService();
		$fields					= 'id,title,type,status,suggest,modified';
		if($type=='comment')
		{
			$fields					= 'id,content,type,status,suggest,modified';
		}
		$this->data['data'] 	= $postService->getList($con,'modified DESC',$start, $num,$fields);
		
		$this->data['types']	= array('1'=>'普通帖子','2'=>'商品分享','0'=>'用户评论');
		
		$count 		= $this->data['data']['count'];
		$baseUrl 	= C('LtUrl')->generate('Post', 'Index', array('p' => ':page'));
		
		$pagination = new LtPagination;
		$pagination->init();
		$this->data['pages'] = $pagination->pager($page, $count, $baseUrl);
		
		$this->data['menu']	= 'topic';
	}
}
